from rest_framework import serializers
from .models import *

# 频道组的序列化器
class GroupSer(serializers.ModelSerializer):
    # 类别名字， 仅仅用于序列化输出
    cate = serializers.PrimaryKeyRelatedField(queryset=Cate.objects.all())
    cate_name = serializers.SerializerMethodField(read_only=True)

    def get_cate_name(self, obj):
        # obj:类别组对象
        return obj.cate.name

    class Meta:
        model = Group
        fields = "__all__"
        read_only_fields = ["id",]





# 一级分类

class CateSer(serializers.ModelSerializer):

    class Meta:
        model = Cate
        fields = "__all__"
